/*
 * Created on Apr 7, 2004
 *
 */
package littlecyberwar.model;

import java.awt.*;
import java.util.*;
import java.io.*;
import javax.swing.text.*;
import littlecyberwar.control.net.*;

/**
 * @author Milton  Soong
 *
 * A holding class for all players information
 */
public class Players implements Serializable {

	private final static Color _selfChatMsgColor = Color.BLACK;
	private final static Color _selfGameMsgColor = Color.RED;
	private final static Color _otherGameMsgColor = Color.RED;
	private final static Color _otherChatMsgColor = Color.BLUE;

	String name;	// the user input name of the player that gets displayed
	IncomingTask incomingTask;	// the incoming task that corresponds to this player
	OutgoingTask outgoingTask;	// the outgoing task that corresponds to this player
	Color chatColor;	// the player color that's used to display chat panel text
	Color msgColor;
	boolean isSelf;
	
	private static HashMap allPlayers= new HashMap(2);
	private static Players self;
	private static String selfName;
	private SimpleAttributeSet chatAttrs;
	private SimpleAttributeSet msgAttrs;
	
	public Players(String nameIn, boolean isSelfIn ) {
		name = nameIn;
		isSelf = isSelfIn;
		
		// for now always use a specific color depending on if it's self or else
		if (isSelf){
			chatColor = _selfChatMsgColor;
			msgColor = 	_selfGameMsgColor;
			
		} else {
			chatColor = _otherChatMsgColor;
			msgColor = 	_otherGameMsgColor;			
		}
		if ( isSelf ){
			self = this;
			selfName = nameIn;
		}
		allPlayers.put(name, this);
		
		// setup msg out attributes
		chatAttrs = new SimpleAttributeSet();
		StyleConstants.setForeground(chatAttrs, chatColor);
		msgAttrs = new SimpleAttributeSet();
		StyleConstants.setForeground(msgAttrs, msgColor);
		StyleConstants.setBold(msgAttrs, true);

	}
	
	public static Players getSelf() {
		return ( self );
	}
	
	public static Players getPlayers( String nameIn ){
		Players p = (Players)allPlayers.get(nameIn);
		if ( p == null ){
			p = new Players(nameIn, false);			 
		}
		return ( p );
	}
	
	/**
	 * @return
	 */
	public Color getChatColor() {
		return chatColor;
	}

	/**
	 * @return
	 */
	public IncomingTask getIncomingTask() {
		return incomingTask;
	}

	/**
	 * @return
	 */
	public boolean isSelf() {
		return isSelf;
	}

	/**
	 * @return
	 */
	public Color getMsgColor() {
		return msgColor;
	}

	/**
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return
	 */
	public OutgoingTask getOutgoingTask() {
		return outgoingTask;
	}

	/**
	 * @param color
	 */
	public void setChatColor(Color color) {
		chatColor = color;
	}

	/**
	 * @param task
	 */
	public void setIncomingTask(IncomingTask task) {
		incomingTask = task;
	}

	/**
	 * @param b
	 */
	public void setSelf(boolean b) {
		isSelf = b;
	}

	/**
	 * @param color
	 */
	public void setMsgColor(Color color) {
		msgColor = color;
	}

	/**
	 * @param string
	 */
	public void setName(String string) {
		name = string;
	}

	/**
	 * @param task
	 */
	public void setOutgoingTask(OutgoingTask task) {
		outgoingTask = task;
	}

	/**
	 * @return
	 */
	public static String getSelfName() {
		return selfName;
	}

	/**
	 * @return
	 */
	public SimpleAttributeSet getChatAttrs() {
		return chatAttrs;
	}

	/**
	 * @return
	 */
	public SimpleAttributeSet getMsgAttrs() {
		return msgAttrs;
	}

}
